using System.Net;
using System.Net.Sockets;

namespace NStun
{
    public class DatagramSocket : Socket
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="DatagramSocket"/> class.
        /// </summary>
        public DatagramSocket()
            : base( AddressFamily.InterNetwork,
                    SocketType.Dgram,
                    ProtocolType.Udp )
        {
            SetSocketOption( SocketOptionLevel.Socket,
                             SocketOptionName.ReuseAddress,
                             1 );
        }

        public DatagramSocket( IPEndPoint localEndPoint ) : this()
        {
            Bind( localEndPoint );
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="DatagramSocket"/> class.
        /// </summary>
        /// <param name="addressFamily">The address family.</param>
        /// <param name="socketType">Type of the socket.</param>
        /// <param name="protocolType">Type of the protocol.</param>
        private DatagramSocket( AddressFamily addressFamily,
                                SocketType socketType,
                                ProtocolType protocolType )
            : this()
        {
        }

        /// <summary>
        /// Sets the socket timeout.
        /// </summary>
        /// <param name="milliseconds">The milliseconds.</param>
        public void SetSocketTimeout( int milliseconds )
        {
            SendTimeout = milliseconds;
            ReceiveTimeout = milliseconds;
        }
    }
}